﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ettevotja_muudatused_tasuta_paring", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EttevotjaMuudatusedTasutaParing))]
    public class EttevotjaMuudatusedTasutaParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEttevotjaMuudatusedTasutaParing clazz;
        
        public EttevotjaMuudatusedTasutaParingSerializer(IEttevotjaMuudatusedTasutaParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kuupaev");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Kuupaev))).ToString());
            Writer.WriteEndElement();
            for (int x = 0; ((clazz.MuudatusteValik != null) 
                        && (x < clazz.MuudatusteValik.Count)); x = (x + 1)) {
                if (clazz.MuudatusteValik[x]!=null) {
                    Writer.WriteStartElement("muudatuste_valik");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MuudatusteValik[x]))).ToString());
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.KandevalisedValik != null) 
                        && (x < clazz.KandevalisedValik.Count)); x = (x + 1)) {
                if (clazz.KandevalisedValik[x]!=null) {
                    Writer.WriteStartElement("kandevalised_valik");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandevalisedValik[x]))).ToString());
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.KandeKandeliigid != null) 
                        && (x < clazz.KandeKandeliigid.Count)); x = (x + 1)) {
                if (clazz.KandeKandeliigid[x]!=null) {
                    Writer.WriteStartElement("kande_kandeliigid");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandeKandeliigid[x]))).ToString());
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.KandeKandeosad != null) 
                        && (x < clazz.KandeKandeosad.Count)); x = (x + 1)) {
                if (clazz.KandeKandeosad[x]!=null) {
                    Writer.WriteStartElement("kande_kandeosad");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeKandeosad[x]))).ToString());
                    Writer.WriteEndElement();
                }
            }
            if (clazz.KandeEelmineStaatus!=null) {
                Writer.WriteStartElement("kande_eelmine_staatus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeEelmineStaatus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeUusStaatus!=null) {
                Writer.WriteStartElement("kande_uus_staatus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KandeUusStaatus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TulemusteLk!=null) {
                Writer.WriteStartElement("tulemuste_lk");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.TulemusteLk))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kuupaev") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>kuupaev");
                }
                clazz.Kuupaev = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kuupaev")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ettevotja_muudatused_tasuta_paring>kuupaev", Reader.LocalName);
            }
            if (Reader.LocalName=="muudatuste_valik") {
                clazz.MuudatusteValik = new System.Collections.Generic.List<System.String>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "muudatuste_valik")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>muudatuste_valik");
                    }
                    clazz.MuudatusteValik.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("muudatuste_valik")).Value);
                }
            }
            if (Reader.LocalName=="kandevalised_valik") {
                clazz.KandevalisedValik = new System.Collections.Generic.List<System.String>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "kandevalised_valik")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>kandevalised_valik");
                    }
                    clazz.KandevalisedValik.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kandevalised_valik")).Value);
                }
            }
            if (Reader.LocalName=="kande_kandeliigid") {
                clazz.KandeKandeliigid = new System.Collections.Generic.List<System.Int32?>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "kande_kandeliigid")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>kande_kandeliigid");
                    }
                    clazz.KandeKandeliigid.Add(new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kande_kandeliigid")).Value);
                }
            }
            if (Reader.LocalName=="kande_kandeosad") {
                clazz.KandeKandeosad = new System.Collections.Generic.List<System.String>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "kande_kandeosad")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>kande_kandeosad");
                    }
                    clazz.KandeKandeosad.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_kandeosad")).Value);
                }
            }
            if (Reader.LocalName=="kande_eelmine_staatus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>kande_eelmine_staatus");
                }
                clazz.KandeEelmineStaatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_eelmine_staatus")).Value;
            }
            if (Reader.LocalName=="kande_uus_staatus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>kande_uus_staatus");
                }
                clazz.KandeUusStaatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kande_uus_staatus")).Value;
            }
            if (Reader.LocalName=="tulemuste_lk") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ettevotja_muudatused_tasuta_paring>tulemuste_lk");
                }
                clazz.TulemusteLk = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("tulemuste_lk")).Value;
            }
        }
    }
}
